package me.yushuai.wukong.base.service;

import me.yushuai.wukong.base.api.dto.*;
import me.yushuai.wukong.common.dto.PageDTO;
import me.yushuai.wukong.common.exceptin.BizIdNotExistException;
import me.yushuai.wukong.common.exceptin.DuplicateBizIdException;
import me.yushuai.wukong.common.exceptin.NotExistException;
import me.yushuai.wukong.common.service.BaseService;

import java.math.BigDecimal;

/**
 * 包装业务接口
 *
 * @author zhoushuai@189.cn
 * @since 2022-08-18
 */
public interface PackingService extends BaseService {

    /**
     * 新建一条包装信息
     *
     * @param dto 包装信息
     * @return 返回包装信息编号
     * @throws DuplicateBizIdException 当包装已存在时抛出异常
     */
    Long createPacking(CreatePackingDTO dto) throws DuplicateBizIdException;

    /**
     * 修改包装信息
     *
     * @param dto 包装信息
     * @return 返回修改后的包装编号
     * @throws NotExistException 当包装不存在时抛出异常
     */
    Long updatePackingById(UpdatePackingDTO dto) throws NotExistException;

    /**
     * 删除一条包装信息
     *
     * @param packingId 包装编号
     * @throws NotExistException 当包装编码不存在时抛出异常
     */
    void deletePacking(Long packingId) throws NotExistException;

    /**
     * 通过ID查询包装的详细信息
     *
     * @param packingId 包装编号
     * @return 返回包规的详细信息
     * @throws NotExistException 当包装不存在时抛出异常
     */
    PackingDTO findPackingById(Long packingId) throws NotExistException;


    /**
     * Query Packing by the bizId, if the bizId not exist throw BizIdNotExistException
     *
     * @param packingBizId the bizId is business id of Packing.
     * @return return PackingDTO with the bizId
     * @throws BizIdNotExistException when the bizId not exist throw exception {@link BizIdNotExistException}
     */
    PackingDTO findPackingByBizId(String packingBizId) throws BizIdNotExistException;

    /**
     * The qtyDto is convert to default uom
     *
     * @param packingId    the packingId is id of Packing
     * @param packingUomId the packingUomId is id of PackingUom, and it's using to qty.
     * @param qty          qty
     * @return convert to qty using default PackingUom by the packingUomId of PackingUom.
     * @throws NotExistException if when the packingUomId and packingId not exists throw NotExistException
     */
    BigDecimal convertQtyToDefaultUom(Long packingUomId, Long packingId, BigDecimal qty) throws NotExistException;

    /**
     * 分页检索包规信息
     *
     * @param dto 检索条件
     * @return 返回包规列表
     */
    PageDTO<PackingDTO> pagingSearchPacking(PagingSearchPacking dto);

    /**
     * 检查包规是否存在
     *
     * @param packingId 包规编号
     * @return 当包规编号存在时返回true否则返回false
     */
    boolean existsByPackingId(Long packingId);

    /**
     * 新建一条包规单位信息
     *
     * @param packingUomDTO 包规单位信息
     * @return 返回包规单位信息编号
     * @throws DuplicateBizIdException 当包规单位已存在时抛出异常
     */
    Long createPackingUom(PackingUomDTO packingUomDTO) throws DuplicateBizIdException;

    /**
     * 修改包规单位信息
     *
     * @param packingUomDTO 包规单位信息
     * @return 返回修改后的包规单位编号
     * @throws NotExistException 当包规单位不存在时抛出异常
     */
    Long updatePackingUomById(PackingUomDTO packingUomDTO) throws NotExistException;

    /**
     * 删除一条包规单位信息
     *
     * @param packingId    产品编号
     * @param packingUomId 包规单位编号
     * @throws NotExistException 当包规单位编码不存在时抛出异常
     */
    void deletePackingUom(Long packingId, Long packingUomId) throws NotExistException;

    /**
     * 通过ID查询包规单位的详细信息
     *
     * @param packingId    包规编号
     * @param packingUomId 包规单位编号
     * @return 返回包规的详细信息
     * @throws NotExistException 当包规单位不存在时抛出异常
     */
    PackingUomDTO findPackingUomById(Long packingId, Long packingUomId) throws NotExistException;

    /**
     * checking the packingUomId of packingId is base uom.
     *
     * @param packingId    id of Packing
     * @param packingUomId id of PackingUom
     * @return It is default packingUom than return true otherwise return false
     * @throws NotExistException when the packingId and packingUomId not exists than throw {@link NotExistException}
     */
    boolean isBasicUom(Long packingId, Long packingUomId) throws NotExistException;

    /**
     * checking the packId and packingUomId is existed.
     *
     * @param packId       packId is id of Packing
     * @param packingUomId packingUomId is id of PackingUom
     * @return when the packingId and packingUomId exists return true otherwise return false.
     */
    boolean existsByPackingUomId(Long packId, Long packingUomId);
}
